import { AdminService } from "../AdminService";
import { Service, Inject } from "typedi";
import { NewCourseModel,updateCourseVideo,UpdateCourse,againUpdateCourseVideo } from "../../model/NewCourseModel";
import { AdminDao } from "../../dao/AdminDao";

@Service()
export class AdminServiceImpl implements AdminService {
	
	@Inject()
	private adminDao:AdminDao;
	
	public async addNewCourse(info: NewCourseModel): Promise<Object> {
		return await this.adminDao.addNewCourseDao(info);
	}
	
	public async updateCourseVideo(Course: [ updateCourseVideo ]): Promise<Object> {
		let list:Object = await this.adminDao.updateCourseVideoDao(Course);
		return list.hasOwnProperty("objectId") ? { res: 'success' } : { res: 'error' };
	}
	
	public async getAllCourse(page: number): Promise<Object> {
		return await this.adminDao.getAllCourseDao(page);
	}
	
	public async getCourseInfo(id: string): Promise<Object> {
		let info = await this.adminDao.getCourseInfoDao(id);
		delete info['createdAt'];
		delete info['updatedAt'];
		info['id'] = info['objectId'];
		delete info['objectId'];
		return info;
	}
	
	public async UpdateCourse(Course: UpdateCourse): Promise<Object> {
		return await this.adminDao.UpdateCourseDao(Course)
	}
	
	public async getVideoList(id: string): Promise<Array<any>> {
		let Video = await this.adminDao.getVideoListDao(id);
		Video.forEach(val => {
			delete val['createdAt'];
			delete val['updatedAt'];
			val['id'] = val['objectId'];
			delete val['objectId'];
		});
		return Video;
	}
	
	public async againUpdateCourseVideo(Course: [ againUpdateCourseVideo ]): Promise<Object> {
		let data = await this.adminDao.againUpdateCourseVideoDao(Course);
		console.log("service",data);
		return data;
	}
	
	public async deleteCourseAndVideo(id: string): Promise<Object> {
		return await this.adminDao.deleteCourseAndVideoDao(id);
	}
	
	public async getAllClass(): Promise<Object> {
		return await this.adminDao.getAllClassDao();
	}
	
	public async deleteClassById(id: string): Promise<Object> {
		return await this.adminDao.deleteClassByIdDao(id);
	}
	
	public async addNewClass(title: string): Promise<Object> {
		return await this.adminDao.addNewClassDao(title);
	}
	
	public async adminLogin(params: Object): Promise<Object> {
		return await this.adminDao.adminLoginDao(params);
	}
	
}